﻿//*** Guidance generated code ***//

using System;
using System.Linq;
using System.Web.Mvc;

using Castle.DynamicProxy;

using ProjectBase.Core;

namespace $safeprojectname$.IoC
{
    public class DaoExceptionFilter : IInterceptor
    {
        protected const string DataLayerError = "Data layer resulted in unexpected state."
                                                + " (See inner exception). "
                                                + " Contact application manager if appropriate";

        public virtual void Intercept(IInvocation invocation)
        {
            try
            {
                invocation.Proceed();
            }
            catch (Exception ex)
            {
                var target = invocation.InvocationTarget ?? invocation.Proxy;

                if (target is IDao) // supports common handling for Data layer troubles
                {
                    throw new DaoException(DataLayerError, ex);
                }
                throw;
            }
        }
    }
}